function Y=odefunction_Amax(t,y)

% ODEFUNCTION_AMAX   calculate the concentration of T,D,S,U

% t   time span
% y   origin concentration of T,D,S,U
% Y   final concentration of T,D,S,U
%
% KaiA   concentration of KaiA
% KaiB   concentration of KaiB
% k1   k_1 in the equilibrium of 'S+B=SB'
% k2   k_-1 in the equilibrium of 'S+B=SB'
% m   parameter for adjustment
% kxy0   k_XY^a0 in equation
% kxyA   k_XY^A in equation
% Khalf   K_1/2 in equation


global KaiA KaiB k1 k2 m kxy0 kxyA Khalf
A=max(0,KaiA-2*m*y(5));
kxy=kxy0+kxyA*A./(Khalf+A);
B=KaiB-y(5);
Y5=k1*y(3)*B-k2*y(5);

Y0=[
    kxy(4,1)*y(4)+kxy(2,1)*y(2)-kxy(1,4)*y(1)-kxy(1,2)*y(1);
    kxy(1,2)*y(1)+kxy(3,2)*(y(3)+y(5))-kxy(2,1)*y(2)-kxy(2,3)*y(2);
    kxy(4,3)*y(4)+kxy(2,3)*y(2)-kxy(3,4)*(y(3)+y(5))-kxy(3,2)*(y(3)+y(5))-Y5;   
    ];

Y=[Y0;
   -Y0(1)-Y0(2)-Y0(3);
   Y5;];